import request from '@/utils/request'

export function login(uploadData) {
  return request({
    url: '/login',
    method: 'post',
    headers: {
      // 'Content-Type': 'multipart/form-data'//含有附件的表单提交的Content-Type
      'Content-Type': 'application/x-www-form-urlencoded'// 普通表单提交的Content-Type
    },
    data: uploadData,
    transformRequest: [data => {
      const formData = new FormData()
      for (const key in uploadData) {
        formData.append(key, uploadData[key])
      }
      return formData
    }]
  })
}

export function getInfo(token) {
  return request({
    url: 'user/1',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// 编辑用户接口
export function editUser(data) {
  return request({
    url: '/user/update',
    data: data,
    method: 'put'
  })
}

// 添加用户接口
export function addUser(data) {
  return request({
    url: '/user/add',
    data: data,
    method: 'post'
  })
}

// 获取用户管理列表
export function getUser() {
  return request({
    url: '/user/page',
    method: 'get'
  })
}

// 删除用户表操作
export function delUser(id) {
  return request({
    url: '/user/' + id,
    method: 'delete'
  })
}

// 通过ID查询用户列表数据
export function queryUserList(id) {
  return request({
    url: '/user/' + id,
    method: 'get'
  })
}
